package com.cheyunkeji.er.view.evaluate;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.view.AbsDialog;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Michael on 2017/7/21 22:33.
 */

public class AppearanceCheckDialog extends AbsDialog implements View.OnClickListener {


    private static final String TAG = AppearanceCheckDialog.class.getSimpleName();
    @BindView(R.id.tv_preview_img)
    TextView tvPreviewImg;
    @BindView(R.id.tv_take_photo)
    TextView tvTakePhoto;
    @BindView(R.id.tv_delete)
    TextView tvDelete;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_gallery)
    TextView tvGallery;

    OnDialogCheckedListener listener;
    View currentLongClickedView;
    @BindView(R.id.rl_preview_img)
    RelativeLayout rlPreviewImg;
    @BindView(R.id.rl_take_photo)
    RelativeLayout rlTakePhoto;
    @BindView(R.id.rl_gallery)
    RelativeLayout rlGallery;
    @BindView(R.id.rl_delete)
    RelativeLayout rlDelete;
    /**
     * 是否点击则取消，默认为true
     */
    private boolean clickCancelable = true;

    public AppearanceCheckDialog(Context context, OnDialogCheckedListener listener) {

        super(context, R.style.dialog_style_dim_3);
        this.listener = listener;

    }

    public View getCurrentLongClickedView() {
        return currentLongClickedView;
    }

    public void setCurrentLongClickedView(View currentLongClickedView) {
        this.currentLongClickedView = currentLongClickedView;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.er_appearance_check_dialog);
        setCanceledOnTouchOutside(false);
        init();
        ButterKnife.bind(this);

        rlPreviewImg.setOnClickListener(this);
        rlTakePhoto.setOnClickListener(this);
        rlDelete.setOnClickListener(this);
        tvCancel.setOnClickListener(this);
        rlGallery.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        if (clickCancelable) dismiss();

        switch (v.getId()) {
            case R.id.rl_preview_img:
                listener.onPreviewImage();
                break;
            case R.id.rl_take_photo:
                listener.onTakePhoto();
                break;
            case R.id.rl_delete:
                listener.onDelete();
                break;
            case R.id.rl_gallery:
                listener.selectImgFromGallery();

            default:
                break;
        }
    }


    public void showDialogWithPreView() {

        show();
        if (rlPreviewImg.getVisibility() == View.GONE) {
            rlPreviewImg.setVisibility(View.VISIBLE);
        }
    }

    public void showDialogWithoutPreview() {

        show();
        if (rlPreviewImg.getVisibility() != View.GONE) {
            rlPreviewImg.setVisibility(View.GONE);
        }
    }


    public interface OnDialogCheckedListener {

        void onPreviewImage();

        void onTakePhoto();

        void onDelete();

        void selectImgFromGallery();
    }

}
